<template>
  <div class="challenge-item">
    <div class="challenge-info">
      <van-image :height="50" :width="50" fit="cover" :src="challenge.image" />
      <div class="challenge-name">
        <div>{{ challenge.name }}</div>
        <div>ID: {{ challenge.id }} {{ challenge.cat_id_name }} ￥{{ challenge.price }}</div>
      </div>
    </div>
    <div class="challenge-controll">
      <VanSwitch @change="emitter('changeStatus', {id: challenge.id, status: challenge.status})"
                 :model-value="challenge.status === 1"></VanSwitch>
      <VanButton @click="emitter('controll')" style="margin-left: 10px;" size="normal" type="primary">操作</VanButton>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue'

defineProps({
  challenge: Object
})

const emitter = defineEmits(['controll', 'changeStatus'])
</script>

<style lang="less" scoped>
.challenge-item {
  width: 100%;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .challenge-info {
    display: flex;
    font-size: 11px;

    .challenge-name {
      margin-left: 10px;
    }
  }

  .challenge-controll {
    display: flex;
    align-items: center;
  }
}
</style>
